package fr.mywiki.model.ejbAdapter.entity;

import java.util.Collection;

import javax.ejb.CreateException;
import javax.ejb.EntityBean;

import fr.mywiki.business.entry.EntryLite;


/**
 * @ejb.bean name="Entry"
 *		local-jndi-name="ejb/MyWiki/Entry"
 *		view-type="local"
 *		cmp-version="2.x"
 *		primkey-field="id"
 *		schema="Entry"
 *
 * @ejb.persistence table-name="entry"
 * 
 * @ejb.finder view-type="local"
 *		signature="java.util.Collection findAll()"
 *		unchecked="true"
 *		query="SELECT OBJECT(e) FROM Entry e"
 *		result-type-mapping="Local"
 * @ejb.finder view-type="local"
 * 		signature="java.util.Collection findByInternTitle(java.lang.String internTitle)"
 * 		unchecked="true"
 *		query="SELECT OBJECT(e) FROM Entry e WHERE e.internTitle=?1"
 *		result-type-mapping="Local"
 * 
 * @author tlombard
 */
public abstract class EntryBean extends EntityAdapter implements EntityBean {
	/**
	 * @ejb.create-method
	 */
	public Long ejbCreate(Long id) throws CreateException {
		setId(id);
		return id;
	}
	
	/**
	 * @ejb.persistent-field
	 * @ejb.interface-method view-type="local"
	 * @ejb.persistence column-name="id"
	 */
	public abstract Long getId();
 
 	/**
	 * @ejb.persistent-field
	 * @ejb.interface-method view-type="local"
	 * @ejb.persistence column-name="id"
	 */
	public abstract void setId(Long id);
	
	/**
	 * @ejb.persistent-field
	 * @ejb.interface-method view-type="local"
	 * @ejb.persistence column-name="internTitle"
	 */
	public abstract String getInternTitle();
 
 	/**
	 * @ejb.persistent-field
	 * @ejb.interface-method view-type="local"
	 * @ejb.persistence column-name="internTitle"
	 */
	public abstract void setInternTitle(String internTitle);
	
	/**
	 * @ejb.persistent-field
	 * @ejb.interface-method view-type="local"
	 * @ejb.persistence column-name="title"
	 */
	public abstract String getTitle();
 
 	/**
	 * @ejb.persistent-field
	 * @ejb.interface-method view-type="local"
	 * @ejb.persistence column-name="title"
	 */
	public abstract void setTitle(String title);
	
	/**
	 * @ejb.interface-method view-type="local"
	 *
	 * @ejb.relation name="Version-to-Entry"
	 *		role-name="Entry-has-many-versions"
	 *		target-role-name="Version-has-one-entry"
	 */
	 public abstract Collection getVersions();

	 /**
	  * @ejb.interface-method
	  */
	public abstract void setVersions(Collection c);

  /**
	 * @ejb.persistent-field
	 * @ejb.interface-method view-type="local"
	 * @ejb.persistence column-name="id_version"
	 */
	public abstract Long getCurrentVersion();
 
 	/**
	 * @ejb.persistent-field
	 * @ejb.interface-method view-type="local"
	 * @ejb.persistence column-name="id_version"
	 */
	public abstract void setCurrentVersion(Long versionId);
  
	/**
	 * @ejb.interface-method view-type="local"
	 */
	public EntryLite getEntryLite() {
		EntryLite entry = new EntryLite();

		entry.setId(getId());
		entry.setInternTitle(getInternTitle());
		entry.setTitle(getTitle());
		entry.setCurrentVersion(getCurrentVersion());
		
		return entry;
	}
}
